<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>English Potential Assessment - Why Learn English</title>
    <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
    <style>
      body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
        background-color: #fff;
        color: #333;
      }

      .dark body {
        background-color: #1a1a1a;
        color: #f5f5f5;
      }

      /* 进度条样式 */
      .progress-container {
        height: 4px;
        width: 100%;
        background-color: #f0f0f0;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
      }

      .progress-bar {
        height: 100%;
        background-color: #007aff;
        width: 50%; /* 8步，第4步 */
      }

      .dark .progress-container {
        background-color: #333;
      }

      /* 顶部导航 */
      .top-nav {
        padding: 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .back-btn {
        color: #007aff;
        font-size: 1.25rem;
        cursor: pointer;
      }

      /* 内容区域 */
      .content {
        max-width: 500px;
        margin: 0 auto;
        padding: 1rem;
      }

      /* 词汇选项卡片样式 */
      .word-item {
        display: flex;
        align-items: center;
        padding: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        margin-bottom: 16px;
        cursor: pointer;
        transition: all 0.2s;
        background-color: white;
      }

      .word-item:hover {
        border-color: #007aff;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
      }

      .word-item.selected {
        border-color: #007aff;
        background-color: rgba(0, 122, 255, 0.1);
      }

      .word-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16px;
        flex-shrink: 0;
        font-size: x-large;
      }

      .word-icon i {
        font-size: 20px;
        color: #007aff;
      }

      .word-content {
        flex-grow: 1;
      }

      .word-title {
        font-weight: 600;
        font-size: 1rem;
        margin-bottom: 4px;
      }

      .word-description {
        font-size: 0.875rem;
        color: #6b7280;
      }

      /* 适配黑暗模式 */
      .dark .word-item {
        background-color: #2d3748;
        border-color: #4a5568;
      }

      .dark .word-icon {
        background-color: #374151;
      }

      .dark .word-description {
        color: #9ca3af;
      }

      .dark .word-item:hover,
      .dark .word-item.selected {
        border-color: #0a84ff;
      }

      .dark .word-item.selected {
        background-color: rgba(10, 132, 255, 0.2);
      }

      /* 按钮样式 */
      .btn-primary {
        background-color: #007aff;
        color: white;
        padding: 0.75rem 1.5rem;
        border-radius: 10px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        width: 100%;
        justify-content: center;
        border: none;
      }

      .btn-primary:hover {
        background-color: #0062cc;
      }

      .btn-primary:disabled {
        background-color: #c7c7cc;
        cursor: not-allowed;
      }

      /* 主题切换按钮 */
      .theme-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #007aff;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        z-index: 1000;
      }

      .theme-toggle:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
      }

      .nav-progress-container {
        display: flex;
        align-items: center;
        margin-bottom: 40px;
        gap: 15px;
      }

      .back-button {
        width: 30px;
        height: 30px;
        border: none;
        background: none;
        cursor: pointer;
        color: #2b85e4;
        font-size: 20px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .back-button svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
      }

      .progress-bar {
        flex: 1;
        height: 6px;
        background-color: #e0e0e0;
        border-radius: 3px;
      }

      .progress {
        height: 100%;
        width: 19.98%;
        background-color: #2b85e4;
        border-radius: 3px;
      }
    </style>
    <script>
      // 检查深色模式
      function checkDarkMode() {
        if (
          localStorage.getItem('darkMode') === 'true' ||
          (localStorage.getItem('darkMode') === null && window.matchMedia('(prefers-color-scheme: dark)').matches)
        ) {
          document.documentElement.classList.add('dark')
          return true
        }
        return false
      }

      // 切换深色/浅色模式
      function toggleDarkMode() {
        if (document.documentElement.classList.contains('dark')) {
          document.documentElement.classList.remove('dark')
          localStorage.setItem('darkMode', 'false')
          document.getElementById('theme-icon').className = 'fas fa-moon'
        } else {
          document.documentElement.classList.add('dark')
          localStorage.setItem('darkMode', 'true')
          document.getElementById('theme-icon').className = 'fas fa-sun'
        }
      }

      function selectOption(element) {
        const nextButton = document.getElementById('next-button')
        // 如果已经选中，取消选中
        if (element.classList.contains('selected')) {
          element.classList.remove('selected')
          nextButton.disabled = true
          nextButton.style.backgroundColor = '#B1D9FF'
          return
        }
        // 移除所有其他选项的选中状态
        document.querySelectorAll('.word-item').forEach(item => {
          item.classList.remove('selected')
        })

        // 添加当前选项的选中状态
        element.classList.add('selected')

        // 获取页面标题和当前页面名称
        const pageTitle = document.querySelector('.text-3xl').textContent.trim()
        const pageName = window.location.pathname.split('/').pop().split('.')[0]
        const selectedValue = element.getAttribute('data-value')
        const selectedTitle = element.querySelector('.word-title').textContent.trim()

        // 创建数据对象
        const data = {
          title: pageTitle,
          value: selectedTitle,
          reason: selectedValue,
        }

        // 以JSON格式存储到localStorage
        localStorage.setItem(pageName, JSON.stringify(data))

        // 保留原有存储方式，以保证兼容性
        localStorage.setItem('selected_english_reason', selectedValue)

        // 启用下一步按钮
        nextButton.disabled = false
        nextButton.style.backgroundColor = '#007aff' // 恢复默认颜色
      }

      // 当DOM加载完成
      document.addEventListener('DOMContentLoaded', function () {
        const isDark = checkDarkMode()
        document.getElementById('theme-icon').className = isDark ? 'fas fa-sun' : 'fas fa-moon'
        const nextButton = document.getElementById('next-button')
        const selectedOptions = document.querySelectorAll('.word-item.selected')
        if (selectedOptions.length === 0) {
          nextButton.disabled = true
          nextButton.style.backgroundColor = '#B1D9FF'
        }
      })
    </script>
  </head>
  <body>
    <!-- 主内容区 -->
    <div class="content">
      <div class="nav-progress-container">
        <button class="back-button" onclick="window.location.href='/level.html'">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
          </svg>
        </button>
        <div class="progress-bar">
          <div class="progress"></div>
        </div>
      </div>
      <!-- 页面标题 -->
      <div class="flex justify-center">
        <h1 class="w-96 text-3xl font-bold text-[#0B4983] text-center">Why do you want to learn English?</h1>
      </div>
      <p class="text-gray-600 dark:text-gray-400 mb-4"></p>

      <!-- 理由选项 -->
      <div>
        <!-- 职业/工作 -->
        <div class="word-item" onclick="selectOption(this)" data-value="career">
          <div class="word-icon">💼</div>
          <div class="word-content">
            <div class="word-title">Career, job</div>
            <div class="word-description"></div>
          </div>
        </div>

        <!-- 家人和朋友 -->
        <div class="word-item" onclick="selectOption(this)" data-value="family_friends">
          <div class="word-icon">👫</div>
          <div class="word-content">
            <div class="word-title">Family and friends</div>
            <div class="word-description"></div>
          </div>
        </div>

        <!-- 旅行 -->
        <div class="word-item" onclick="selectOption(this)" data-value="travels">
          <div class="word-icon">✈️</div>
          <div class="word-content">
            <div class="word-title">Travels</div>
            <div class="word-description"></div>
          </div>
        </div>

        <!-- 与伙伴交流 -->
        <div class="word-item" onclick="selectOption(this)" data-value="communicating_partners">
          <div class="word-icon">👩‍❤️‍👨</div>
          <div class="word-content">
            <div class="word-title">Communicating with partners</div>
            <div class="word-description"></div>
          </div>
        </div>

        <!-- 大脑训练 -->
        <div class="word-item" onclick="selectOption(this)" data-value="brain_training">
          <div class="word-icon">🧠</div>
          <div class="word-content">
            <div class="word-title">Brain training</div>
            <div class="word-description"></div>
          </div>
        </div>

        <!-- 教育 -->
        <div class="word-item" onclick="selectOption(this)" data-value="education">
          <div class="word-icon">🎓</div>
          <div class="word-content">
            <div class="word-title">Education</div>
            <div class="word-description"></div>
          </div>
        </div>
      </div>

      <!-- 下一步按钮 -->
      <button id="next-button" disabled class="btn-primary mt-6" onclick="window.location.href='/whatLevel.html'">
        下一步 <i class="fas fa-arrow-right ml-2"></i>
      </button>
    </div>

    <!-- 主题切换按钮 -->
    <div class="theme-toggle" onclick="toggleDarkMode()">
      <i id="theme-icon" class="fas fa-moon"></i>
    </div>
  </body>
</html>
